//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _CINEMATIC_THREAD_H_
#define _CINEMATIC_THREAD_H_

#include "stdafx.h"
#include "../FileSystem/irrArray.h"
#include "../FileSystem/IrrString.h"
#include "../FileSystem/IAttributes.h"

#define FINAL_ACTION_TIME		60.0f

class Camera;
class Player;
class GameObjectList;

namespace irr 
{
	namespace io
	{
		class IAttributes;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
class CinematicCommand;
class GameObject;
class Cinematic;
class GameObjectListInterface;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
enum 
{
	E_THREAD_TYPE_OBJ = 0,
	E_THREAD_TYPE_BASIC = 1,
	E_THREAD_TYPE_CAMERA = 2,
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
typedef struct {
	
	float m_Time;
	s32 m_CurrentStep;
	array<CinematicCommand*>	m_CommandData;

} SCinematicEvent;

enum
{
	CMD_ENABLEOBJ = 0,
	CMD_MOVETO,
	CMD_PLAYTUTO,
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
class CinematicThread
{
	public:
		CinematicThread();
		~CinematicThread();

		void SaveData(CWriteFile* stream);
		void LoadData(CReadFile* stream);
		
		bool Init(int id, Cinematic *owner );
		bool Update( float time );

		s32						m_Id;	
		s32						m_Type;		
		s32						m_ObjId;
		stringw				m_Name;
		s32						m_lastExecutedEvent;
		float							m_currentTime;
		s32						m_InstructionPointer;
		array<SCinematicEvent*>  m_CinematicEvent;
		GameObject*						m_Obj;
		Cinematic*						m_owner;

		//Camera*							GetCamera();
		//Player*							GetPlayer();
		GameObjectListInterface&		GetGameObjects();
		//GameObjectListInterface&		GetGenericWPs();
		//GameObjectListInterface&		GetCinematicObjects();


		bool							m_isActive;

		bool							m_hasFinalState;
		//bool							m_isInCutscene;

		void doFinalAction ();
		void reset ();
		//void SetThreadInCutscene ();
	private:
		
		
		//bool m_bTestResult;
		//bool m_bIsTest;

		bool doCommand(CinematicCommand*);
		bool executeCommand(SCinematicEvent* );

		bool EnableObject(IAttributes* attr);
		bool MoveTo(IAttributes* attr);
		bool PlayTuto(IAttributes* attr);

};

#endif